package org.java8newfeature.stream;

import java.util.Arrays;
import java.util.List;

public class Section10 {
    public static void main(String[] args) {
        List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);

        Integer result = numbers
                .stream()
                .reduce(0, (subTotal,element)->subTotal+element);
        System.out.println(result);

        System.out.println(numbers.stream().reduce(Integer::sum).get());
        Integer result2 = numbers
                .stream()//todo identidy  累加值
                .reduce(3, Integer::sum);
        System.out.println(result2);

        List<String> letters = Arrays.asList("a", "b", "c", "d", "e");
        String result3 = letters
                .stream()
                .reduce("", (partialString, element) -> partialString + element);
        System.out.println(result);  //abcde

        String result4 = letters
                .stream()
                .reduce("123", String::concat);
        System.out.println(result4);

        Employee e1 = new Employee(1,23,"M","Rick","Beethovan");
        Employee e2 = new Employee(2,13,"F","Martina","Hengis");
        Employee e3 = new Employee(3,43,"M","Ricky","Martin");
        Employee e4 = new Employee(4,26,"M","Jon","Lowman");
        Employee e5 = new Employee(5,19,"F","Cristine","Maria");
        Employee e6 = new Employee(6,15,"M","David","Feezor");
        Employee e7 = new Employee(7,68,"F","Melissa","Roy");
        Employee e8 = new Employee(8,79,"M","Alex","Gussin");
        Employee e9 = new Employee(9,15,"F","Neetu","Singh");
        Employee e10 = new Employee(10,45,"M","Naveen","Jain");


      /*  List<Employee> employees = Arrays.asList(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10);
        Integer result1 = employees
                .stream()
                .map(employee -> employee.getAge() ).reduce(0, Integer::sum);
        System.out.println(result1);*/

       /* Integer reduce = employees
                .stream()
                .reduce(0, (subTotal, Element) -> subTotal + Element.getAge(),Integer::sum);
        System.out.println(reduce);
*/
    }
}
